package cn.nubia.admin.admin.controller;

import cn.nubia.admin.common.constant.SystemConstant;
import cn.nubia.admin.common.springmvc.WebContext;
import cn.nubia.admin.sysconfig.service.SysConfigService;
import cn.nubia.admin.sysconfig.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

/**
 * Created by Administrator on 2015/6/26.
 */
@Controller
public class AdminController {


    @Autowired
    SysConfigService sysConfigService;

    @Autowired
    UserService userService;

    /**
     * 默认匹配所有地址.
     *
     * @return
     * @author cnJason
     */
    @RequestMapping("/**")
    public ModelAndView defaultMapping() {
        return new ModelAndView();
    }

    @RequestMapping("/index")
    public ModelAndView index(Integer moduleId){
        ModelAndView modelAndView =new ModelAndView();
        Object oldModuleId = WebContext.getAttr(WebContext.MODULE_ID);
        if(moduleId!=null){
            WebContext.setToCache(WebContext.MODULE_ID,moduleId);
        }else{
            if(oldModuleId == null)WebContext.setToCache(WebContext.MODULE_ID,SystemConstant.getDefaultMenuId());
            moduleId =SystemConstant.getDefaultMenuId();
        }
        modelAndView.addObject("currMenu", SystemConstant.getMenu(moduleId));
        modelAndView.addObject("sysmenus", SystemConstant.menus);
        return modelAndView;
    }

}
